import { createRouter, createWebHistory } from 'vue-router'
import { routes } from './route'

const { VITE_PUBLIC_PATH, VITE_ENV } = import.meta.env

const router = createRouter({
  history: createWebHistory(VITE_PUBLIC_PATH),
  routes,
  scrollBehavior(to, from, savedPosition): any {
    if (savedPosition) {
      // 如果之前有保存滚动位置，则恢复到之前保存的位置
      return savedPosition
    } else {
      // 否则，默认滚动到页面顶部
      return { x: 0, y: 0 }
    }
  },
})

export default router
